﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;
namespace WebApp.Management
{
    public partial class indexs : PageBase2
    {
        private UserManager m_UserManager = new UserManager();
        private RoleManager m_RoleManager = new RoleManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                Cosmetic.DataEntity.User theUser = (this.Page as PageBase2).SignInUser1;

            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Cosmetic.DataEntity.User theUser = this.m_UserManager.LoginValidate(this.txtUserName.Text.Trim(), this.txtUserPass.Text);
            if (null == theUser)
            {
                Session.Remove("SignInUser1");
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('用户名/密码无效!');", true);
                return;
            }

            if (!this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Admin) &&
                //!this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Blog) &&
                !this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Product))
            {
                Session.Remove("SignInUser1");
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('你没有管理员权限!');", true);
                return;
            }
            //if (this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Blog))
            //{

            //    this.SignInUser1 = theUser;
            //    Response.Redirect("welcome.aspx");
            //}
            if (this.m_RoleManager.CheckUserRole(theUser, RoleManager.ERole.Product))
            {
                this.SignInUser1 = theUser;
                Response.Redirect("welcome.html");
            }
            else
            {
                this.SignInUser1 = theUser;
                this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, "alert('登录成功!');", true);

                Response.Redirect("Adminwelcome.aspx");
            }
        }
    }
}
